This is Info file diff.info, produced by Makeinfo-1.51 from the input file ./diff.texi. This file documents the the GNU `diff', `diff3', `sdiff', and `cmp' commands for showing the differences between text files and the `patch' command for using their output to update files. Copyright (C) 1992, 1993 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Foundation. File: diff.info, Node: diff Options, Up: Invoking diff Options to `diff' ================= Below is a summary of all of the options that GNU `diff' accepts. Most options have two equivalent names, one of which is a single letter preceded by `-', and the other of which is a long name preceded by `--'. Multiple single letter options (unless they take an argument) can be combined into a single command line word: `-ac' is equivalent to `-a -c'. Long named options can be abbreviated to any unique prefix of their name. Brackets ([ and ]) indicate that an option takes an optional argument. `-LINES' Show LINES (an integer) lines of context. This option does not specify an output format by itself; it has no effect unless it is combined with `-c' (*note Context Format::.) or `-u' (*note Unified Format::.). This option is obsolete. Treat all files as text and compare them line-by-line, even if they do not seem to be text. *Note Binary::. Ignore changes in amount of blank and tab whitespace. *Note Whitespace::. Ignore changes that just insert or delete blank lines. *Note Blank Lines::. `--brief' Report only whether the files differ, not the details of the differences. *Note Brief::. Use the context output format. *Note Context Format::. `-C LINES' `--context[=LINES]' Use the context output format, showing LINES (an integer) lines of context, or three if LINES is not given. *Note Context Format::. `--changed-group-format=FORMAT' Use FORMAT to output a line group containing differing lines from both files in if-then-else format. *Note Line Group Formats::. Change the algorithm perhaps find a smaller set of changes. This makes `diff' slower (sometimes much slower). *Note diff Performance::. `-D NAME' Make merged `#ifdef' format output, conditional on the preprocessor macro NAME. *Note If-then-else::. `--ed' Make output that is a valid `ed' script. *Note ed Scripts::. `--exclude=PATTERN' When comparing directories, ignore files and subdirectories whose basenames match PATTERN. *Note Comparing Directories::. `--exclude-from=FILE' When comparing directories, ignore files and subdirectories whose basenames match any pattern contained in FILE. *Note Comparing Directories::. `--expand-tabs' Expand tabs to spaces in the output, to preserve the alignment of tabs in the input files. *Note Tabs::. Make output that looks vaguely like an `ed' script but has changes in the order they appear in the file. *Note Forward ed::. `-F REGEXP' In context and unified format, for each hunk of differences, show some of the last preceding line that matches REGEXP. *Note Specified Headings::. `--forward-ed' Make output that looks vaguely like an `ed' script but has changes in the order they appear in the file. *Note Forward ed::. This option currently has no effect; it is present for Unix compatibility. Use heuristics to speed handling of large files that have numerous scattered small changes. *Note diff Performance::. Ignore changes in case; consider upper- and lower-case letters equivalent. *Note Case Folding::. `-I REGEXP' Ignore changes that just insert or delete lines that match REGEXP. *Note Specified Folding::. `--ifdef=NAME' Make merged if-then-else output using FORMAT. *Note If-then-else::. `--ignore-all-space' Ignore whitespace when comparing lines. *Note Whitespace::. `--ignore-blank-lines' Ignore changes that just insert or delete blank lines. *Note Blank Lines::. `--ignore-case' Ignore changes in case; consider upper- and lower-case to be the same. *Note Case Folding::. `--ignore-matching-lines=REGEXP' Ignore changes that just insert or delete lines that match REGEXP. *Note Specified Folding::. `--ignore-space-change' Ignore changes in amount of blank and tab whitespace. *Note Whitespace::. `--initial-tab' Output a tab rather than a space before the text of a line in normal or context format. This causes the alignment of tabs in the line to look normal. *Note Tabs::. Pass the output through `pr' to paginate it. *Note Pagination::. `-L LABEL' Use LABEL instead of the file name in the context format (*note Context Format::.) and unified format (*note Unified Format::.) headers. *Note RCS::. `--label=LABEL' Use LABEL instead of the file name in the context format (*note Context Format::.) and unified format (*note Unified Format::.) headers. `--left-column' Print only the left column of two common lines in side by side format. *Note Side by Side Format::. `--minimal' Change the algorithm to perhaps find a smaller set of changes. This makes `diff' slower (sometimes much slower). *Note diff Performance::. Output RCS-format diffs; like `-f' except that each command specifies the number of lines affected. *Note RCS::. `--new-file' In directory comparison, if a file is found in only one directory, treat it as present but empty in the other directory. *Note Comparing Directories::. `--new-group-format=FORMAT' Use FORMAT to output a group of lines taken from just the second file in if-then-else format. *Note Line Group Formats::. `--new-line-format=FORMAT' Use FORMAT to output a line taken from just the second file in if-then-else format. *Note Line Formats::. `--old-group-format=FORMAT' Use FORMAT to output a group of lines taken from just the first file in if-then-else format. *Note Line Group Formats::. `--old-line-format=FORMAT' Use FORMAT to output a line taken from just the first file in if-then-else format. *Note Line Formats::. Show which C function each change is in. *Note C Function Headings::. When comparing directories, if a file appears only in the second directory of the two, treat it as present but empty in the other. `--paginate' Pass the output through `pr' to paginate it. *Note Pagination::. Report only whether the files differ, not the details of the differences. *Note Brief::. When comparing directories, recursively compare any subdirectories found. *Note Comparing Directories::. `--rcs' Output RCS-format diffs; like `-f' except that each command specifies the number of lines affected. *Note RCS::. `--recursive' When comparing directories, recursively compare any subdirectories found. *Note Comparing Directories::. `--report-identical-files' Report when two files are the same. *Note Comparing Directories::. Report when two files are the same. *Note Comparing Directories::. `-S FILE' When comparing directories, start with the file FILE. This is used for resuming an aborted comparison. *Note Comparing Directories::. `--sdiff-merge-assist' Print extra information to help `sdiff'. `sdiff' uses this option when it runs `diff'. This option is not intended for users to use directly. `--show-c-function' Show which C function each change is in. *Note C Function Headings::. `--show-function-line=REGEXP' In context and unified format, for each hunk of differences, show some of the last preceding line that matches REGEXP. *Note Specified Headings::. `--side-by-side' Use the side by side output format. *Note Side by Side Format::. `--speed-large-files' Use heuristics to speed handling of large files that have numerous scattered small changes. *Note diff Performance::. `--starting-file=FILE' When comparing directories, start with the file FILE. This is used for resuming an aborted comparison. *Note Comparing Directories::. `--suppress-common-lines' Do not print common lines in side by side format. *Note Side by Side Format::. Expand tabs to spaces in the output, to preserve the alignment of tabs in the input files. *Note Tabs::. Output a tab rather than a space before the text of a line in normal or context format. This causes the alignment of tabs in the line to look normal. *Note Tabs::. `--text' Treat all files as text and compare them line-by-line, even if they do not appear to be text. *Note Binary::. Use the unified output format. *Note Unified Format::. `--unchanged-group-format=FORMAT' Use FORMAT to output a group of common lines taken from both files in if-then-else format. *Note Line Group Formats::. `--unchanged-line-format=FORMAT' Use FORMAT to output a line common to both files in if-then-else format. *Note Line Formats::. `--unidirectional-new-file' When comparing directories, if a file appears only in the second directory of the two, treat it as present but empty in the other. *Note Comparing Directories::. `-U LINES' `--unified[=LINES]' Use the unified output format, showing LINES (an integer) lines of context, or three if LINES is not given. *Note Unified Format::. `--version' Output the version number of `diff'. Ignore horizontal whitespace when comparing lines. *Note Whitespace::. `-W COLUMNS' `--width=COLUMNS' Use an output width of COLUMNS in side by side format. *Note Side by Side Format::. `-x PATTERN' When comparing directories, ignore files and subdirectories whose basenames match PATTERN. *Note Comparing Directories::. `-X FILE' When comparing directories, ignore files and subdirectories whose basenames match any pattern contained in FILE. *Note Comparing Directories::. Use the side by side output format. *Note Side by Side Format::. File: diff.info, Node: Invoking diff3, Next: Invoking patch, Prev: Invoking diff, Up: Top Invoking `diff3' **************** The `diff3' command compares three files and outputs descriptions of their differences. Its arguments are as follows: diff3 OPTIONS... MINE OLDER YOURS The files to compare are MINE, OLDER, and YOURS. At most one of these three file names may be `-', which tells `diff3' to read the standard input for that file. An exit status of 0 means `diff3' was successful, 1 means some conflicts were found, and 2 means trouble. * Menu: * diff3 Options:: Summary of options to `diff3'. File: diff.info, Node: diff3 Options, Up: Invoking diff3 Options to `diff3' ================== Below is a summary of all of the options that GNU `diff3' accepts. Multiple single letter options (unless they take an argument) can be combined into a single command line argument. Treat all files as text and compare them line-by-line, even if they do not appear to be text. *Note Binary::. Incorporate all changes from OLDER to YOURS into MINE, surrounding all conflicts with bracket lines. *Note Marking Conflicts::. Generate an `ed' script that incorporates all the changes from OLDER to YOURS into MINE. *Note Which Changes::. Like `-e', except bracket lines from overlapping changes' first and third files. *Note Marking Conflicts::. With `-e', an overlapping change looks like this: <<<<<<< MINE lines from MINE ======= lines from YOURS >>>>>>> YOURS `--ed' Generate an `ed' script that incorporates all the changes from OLDER to YOURS into MINE. *Note Which Changes::. `--easy-only' Like `-e', except output only the nonoverlapping changes. *Note Which Changes::. Generate `w' and `q' commands at the end of the `ed' script for System V compatibility. This option must be combined with one of the `-AeExX3' options, and may not be combined with `-m'. *Note Saving the Changed File::. `-L LABEL' `--label=LABEL' Use the label LABEL for the brackets output by the `-A', `-E' and `-X' options. This option may be given up to three times, one for each input file. The default labels are the names of the input files. Thus `diff3 -L X -L Y -L Z -m A B C' acts like `diff3 -m A B C', except that the output looks like it came from files named `X', `Y' and `Z' rather than from files named `A', `B' and `C'. *Note Marking Conflicts::. `--merge' Apply the edit script to the first file and send the result to standard output. Unlike piping the output from `diff3' to `ed', this works even for binary files and incomplete lines. `-A' is assumed if no edit script option is specified. *Note Bypassing ed::. `--overlap-only' Like `-e', except output only the overlapping changes. *Note Which Changes::. `--show-all' Incorporate all unmerged changes from OLDER to YOURS into MINE, surrounding all overlapping changes with bracket lines. *Note Marking Conflicts::. `--show-overlap' Like `-e', except bracket lines from overlapping changes' first and third files. *Note Marking Conflicts::. `--text' Treat all files as text and compare them line-by-line, even if they do not appear to be text. *Note Binary::. `--version' Output the version number of `diff3'. Like `-e', except output only the overlapping changes. *Note Which Changes::. Like `-E', except output only the overlapping changes. In other words, like `-x', except bracket changes as in `-E'. *Note Marking Conflicts::. Like `-e', except output only the nonoverlapping changes. *Note Which Changes::. File: diff.info, Node: Invoking patch, Next: Invoking sdiff, Prev: Invoking diff3, Up: Top Invoking `patch' **************** Normally `patch' is invoked like this: patch g \ No newline at end of file (The exact message may differ in non-English locales.) `diff -n F G' outputs the following without a trailing newline: d1 1 a1 1 g `diff -e F G' reports two errors and outputs the following: 1c g . File: diff.info, Node: Projects, Next: Concept Index, Prev: Incomplete Lines, Up: Top Future Projects *************** Here are some ideas for improving GNU `diff' and `patch'. The GNU project has identified some improvements as potential programming projects for volunteers. You can also help by reporting any bugs that you find. If you are a programmer and would like to contribute something to the GNU project, please consider volunteering for one of these projects. If you are seriously contemplating work, please write to `gnu@prep.ai.mit.edu' to coordinate with other volunteers. * Menu: * Shortcomings:: Suggested projects for improvements. * Bugs:: Reporting bugs. File: diff.info, Node: Shortcomings, Next: Bugs, Up: Projects Suggested Projects for Improving GNU `diff' and `patch' ======================================================= One should be able to use GNU `diff' to generate a patch from any pair of directory trees, and given the patch and a copy of one such tree, use `patch' to generate a faithful copy of the other. Unfortunately, some changes to directory trees cannot be expressed using current patch formats; also, `patch' does not handle some of the existing formats. These shortcomings motivate the following suggested projects. * Menu: * Changing Structure:: Handling changes to the directory structure. * Special Files:: Handling symbolic links, device special files, etc. * Unusual File Names:: Handling file names that contain unusual characters. * Arbitrary Limits:: Patching non-text files. * Large Files:: Handling files that do not fit in memory. * Ignoring Changes:: Ignoring certain changes while showing others. File: diff.info, Node: Changing Structure, Next: Special Files, Up: Shortcomings Handling Changes to the Directory Structure ------------------------------------------- `diff' and `patch' do not handle some changes to directory structure. For example, suppose one directory tree contains a directory named `D' with some subsidiary files, and another contains a file with the same name `D'. `diff -r' does not output enough information for `patch' to transform the the directory subtree into the file. There should be a way to specify that a file has been deleted without having to include its entire contents in the patch file. There should also be a way to tell `patch' that a file was renamed, even if there is no way for `diff' to generate such information. These problems can be fixed by extending the `diff' output format to represent changes in directory structure, and extending `patch' to understand these extensions. File: diff.info, Node: Special Files, Next: Unusual File Names, Prev: Changing Structure, Up: Shortcomings Files that are Neither Directories Nor Regular Files ---------------------------------------------------- Some files are neither directories nor regular files: they are unusual files like symbolic links, device special files, named pipes, and sockets. Currently, `diff' treats all these files like regular files. However, this means that `patch' cannot represent changes to such files. For example, if you change which file a symbolic link points to, `diff' outputs the difference between the two files, instead of the change to the symbolic link. `diff' should optionally report changes to special files specially, and `patch' should be extended to understand these extensions. File: diff.info, Node: Unusual File Names, Next: Arbitrary Limits, Prev: Special Files, Up: Shortcomings File Names that Contain Unusual Characters ------------------------------------------ When a file name contains an unusual character like a newline or whitespace, `diff -r' generates a patch that `patch' cannot parse. The problem is with format of `diff' output, not just with `patch', because with odd enough file names one can cause `diff' to generate a patch that is syntactically correct but patches the wrong files. The format of `diff' output should be extended to handle all possible file names. File: diff.info, Node: Arbitrary Limits, Next: Large Files, Prev: Unusual File Names, Up: Shortcomings Arbitrary Limits ---------------- GNU `diff' can analyze files with arbitrarily long lines and files that end in incomplete lines. However, `patch' cannot patch such files. The `patch' internal limits on line lengths should be removed, and `patch' should be extended to parse `diff' reports of incomplete lines. File: diff.info, Node: Large Files, Next: Ignoring Changes, Prev: Arbitrary Limits, Up: Shortcomings Handling Files that Do Not Fit in Memory ---------------------------------------- `diff' operates by reading both files into memory. This method fails if the files are too large, and `diff' should have a fallback. One way to do this is to scan the files sequentially to compute hash codes of the lines and put the lines in equivalence classes based only on hash code. Then compare the files normally. This does produce some false matches. Then scan the two files sequentially again, checking each match to see whether it is real. When a match is not real, mark both the "matching" lines as changed. Then build an edit script as usual. The output routines would have to be changed to scan the files sequentially looking for the text to print. File: diff.info, Node: Ignoring Changes, Prev: Large Files, Up: Shortcomings Ignoring Certain Changes ------------------------ It would be nice to have a feature for specifying two strings, one in FROM-FILE and one in TO-FILE, which should be considered to match. Thus, if the two strings are `foo' and `bar', then if two lines differ only in that `foo' in file 1 corresponds to `bar' in file 2, the lines are treated as identical. It is not clear how general this feature can or should be, or what syntax should be used for it. File: diff.info, Node: Bugs, Prev: Shortcomings, Up: Projects Reporting Bugs ============== If you think you have found a bug in GNU `cmp', `diff', `diff3', `sdiff', or `patch', please report it by electronic mail to `bug-gnu-utils@prep.ai.mit.edu'. Send as precise a description of the problem as you can, including sample input files that produce the bug, if applicable. Because Larry Wall has not released a new version of `patch' since mid 1988 and the GNU version of `patch' has been changed since then, please send bug reports for `patch' by electronic mail to both `bug-gnu-utils@prep.ai.mit.edu' and `lwall@netlabs.com'. File: diff.info, Node: Concept Index, Prev: Projects, Up: Top Concept Index ************* * Menu: * cmp invocation: Invoking cmp. * cmp options: cmp Options. * diff3 hunks: diff3 Hunks. * diff3 invocation: Invoking diff3. * diff3 options: diff3 Options. * diff3 sample input: Sample diff3 Input. * diff invocation: Invoking diff. * diff options: diff Options. * diff sample input: Sample diff Input. * ed script output format: ed Scripts. * ifdef output format: If-then-else. * patch input format: patch Input. * patch invocation: Invoking patch. * patch messages and questions: patch Messages. * patch options: patch Options. * sdiff invocation: Invoking sdiff. * sdiff options: sdiff Options. * sdiff output format: sdiff Option Summary. * ! output format: Context. * +- output format: Unified Format. * <<<<<<< for marking conflicts: Marking Conflicts. * < output format: Normal. * aligning tabstops: Tabs. * alternate file names: Alternate Names. * backup file names: Backups. * binary file diff: Binary. * binary file patching: Arbitrary Limits. * blank and tab difference suppression: Whitespace. * blank line difference suppression: Blank Lines. * brief difference reports: Brief. * bug reports: Bugs. * C function headings: C Function Headings. * C if-then-else output format: If-then-else. * case difference suppression: Case Folding. * columnar output: Side by Side. * comparing three files: Comparing Three Files. * conflict: diff3 Merging. * conflict marking: Marking Conflicts. * context output format: Context. * diagnostics from patch: patch Messages. * diff merging: Interactive Merging. * directories and patch: patch Directories. * directory structure shanges: Changing Structure. * empty files, removing: Empty Files. * file name alternates: Alternate Names. * file names with unusual characters: Unusual File Names. * format of diff3 output: Comparing Three Files. * format of diff output: Output Formats. * formats for if-then-else line groups: Line Group Formats. * forward ed script output format: Forward ed. * full lines: Incomplete Lines. * function headings, C: C Function Headings. * fuzz factor when patching: Inexact. * headings: Sections. * hunks: Hunks. * hunks for diff3: diff3 Hunks. * if-then-else output format: If-then-else. * imperfect patch application: Imperfect. * incomplete line merging: Merging Incomplete Lines. * incomplete lines: Incomplete Lines. * inexact patches: Inexact. * interactive merging: Interactive Merging. * introduction: Comparison. * invoking cmp: Invoking cmp. * invoking diff3: Invoking diff3. * invoking diff: Invoking diff. * invoking patch: Invoking patch. * invoking sdiff: Invoking sdiff. * large files: Large Files. * line formats: Line Formats. * line group formats: Line Group Formats. * merge commands: Merge Commands. * merged diff3 format: Bypassing ed. * merged output format: If-then-else. * merging from a common ancestor: diff3 Merging. * merging interactively: Merge Commands. * messages from patch: patch Messages. * multiple patches: Multiple Patches. * newline treatment by diff: Incomplete Lines. * normal output format: Normal. * options for cmp: cmp Options. * options for diff3: diff3 Options. * options for diff: diff Options. * options for patch: patch Options. * options for sdiff: sdiff Options. * output formats: Output Formats. * overlap: diff3 Merging. * overlapping change, selection of: Which Changes. * overview of diff and patch: Overview. * paginating diff output: Pagination. * patch making tips: Making Patches. * patching directories: patch Directories. * performance of diff: diff Performance. * projects for directories: Shortcomings. * RCS script output format: RCS. * regular expression matching headings: Specified Headings. * regular expression suppression: Specified Folding. * reject file names: Rejects. * removing empty files: Empty Files. * reporting bugs: Bugs. * reversed patches: Reversed Patches. * sample input for diff3: Sample diff3 Input. * sample input for diff: Sample diff Input. * script output formats: Scripts. * section headings: Sections. * side by side: Side by Side. * side by side format: Side by Side Format. * special files: Special Files. * specified headings: Specified Headings. * summarizing which files differ: Brief. * System V diff3 compatibility: Saving the Changed File. * tab and blank difference suppression: Whitespace. * tabstop alignment: Tabs. * text versus binary diff: Binary. * tips for patch making: Making Patches. * two-column output: Side by Side. * unified output format: Unified Format. * unmerged change: Which Changes. * whitespace in patches: Changed Whitespace.